一种 历史分歧 发生在仓库的时间线分裂为多个非线性路径时。通常在功能分支(如 news-hotfix)与主分支在共享一个共同祖先后独立发展时发生。这种分叉导致快照的内部结构变得复杂。
1. 分叉触发条件
当开发者在本地分支上执行 git commit 时,而上游分支也接收到新的快照(例如对 index.html的更新)。这会产生一个 拓扑间隙 ,使你对 about/me.html 的工作不再基于最新的项目状态。
2. 非线性带来的代价
虽然 Git 通过 递归合并来处理分歧,但由此产生的历史记录往往充满“合并分支…”类的提交。这使得 仓库历史 难以审计,因为 git add 和 git commit 等文件上的操作序列 news-2.html 和 about/me.html 在视觉上交错出现。
3. 快照断连
每次提交都会创建一个完整的 快照。当历史发生分歧时,你的功能分支的 内部结构 缺乏其他地方并发更改的上下文,因此需要采用类似变基的策略来重新对齐项目时间线。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
What primary action triggers a divergent history in Git?
Deleting a branch locally.
Running git commit on a branch after the main branch has moved forward.
Staging files with git add without committing.
Checking out a new branch without making changes.
✅ Correct!
Divergence happens when both the feature branch and its parent branch receive new commits independently.❌ Incorrect
Divergence requires simultaneous evolution of two different branches.QUESTION 2
What is a negative consequence of 'braided' or non-linear history?
It corrupts the files in the working directory.
It prevents Git from tracking file changes.
It makes the repository history difficult to audit and follow logically.
It disables the use of the git status command.
✅ Correct!
Interleaved commits and frequent merge commits obscure the project's logical progression.❌ Incorrect
Git still tracks changes, but the 'log' becomes messy and harder for humans to read.QUESTION 3
Which file update in the example caused the 'upstream' branch to move ahead?
news-2.html
index.html
about/me.html
mary-bio.html
✅ Correct!
In the scenario, a colleague pushing changes to index.html created the upstream shift.❌ Incorrect
news-2.html and about/me.html were the local changes on the feature branch.QUESTION 4
When history diverges, what does the internal makeup of the feature branch lack?
The latest commit hashes from the local index.
The context of concurrent changes made in other branches.
The ability to run git status.
The connection to the initial root commit.
✅ Correct!
The feature branch 'forks' and is unaware of new snapshots created on the main branch.❌ Incorrect
Branches always share a root, but they lose a shared *current* baseline.QUESTION 5
Which Git command is most useful for visualizing a divergent history graph?
git commit -a
git log --oneline --graph
git add -u
git status
✅ Correct!
The --graph flag visually renders the branches and merge points in the terminal.❌ Incorrect
git status shows the working tree, not the historical graph.Case Study: The news-hotfix Divergence
Analyzing a repository split.
You are working on a 'news-hotfix' branch. You perform 'git add news-2.html' and 'git commit'. Simultaneously, your lead developer pushes a change to 'index.html' on the main branch. You then add 'about/me.html' and commit again.
Q
1. Explain why the news-hotfix branch is now considered 'diverged'.
Solution:
It is diverged because its lineage is missing the 'index.html' snapshot that now exists on the main branch tip. Both branches have a shared ancestor, but they have unique, conflicting tips.
It is diverged because its lineage is missing the 'index.html' snapshot that now exists on the main branch tip. Both branches have a shared ancestor, but they have unique, conflicting tips.
Q
2. What will the 'git log --oneline --graph' look like if you perform a standard merge now?
Solution:
It will show two parallel tracks that eventually rejoin at a 'Merge branch' commit, creating a 'bubble' or 'braided' look in the history.
It will show two parallel tracks that eventually rejoin at a 'Merge branch' commit, creating a 'bubble' or 'braided' look in the history.
Q
3. How does this divergence affect the 'internal makeup' of your snapshots?
Solution:
Your latest snapshots do not include the changes to 'index.html', meaning your local feature state is 'stale' relative to the most current version of the project.
Your latest snapshots do not include the changes to 'index.html', meaning your local feature state is 'stale' relative to the most current version of the project.